<?php

namespace app\api\model;

class UserRedbagLogModel extends BaseModel
{
    protected $pk = 'id';
    protected $table = 'hs_user_redbag_log';
    protected static $tableName = 'user_redbag_log';


    public function getCreateTimeAttr($value)
    {
        return date('Y-m-d H:i:s', $value);
    }

    public static function lst($params)
    {
        $page = isset($params['page']) ? $params['page'] : 1;
        $limit = isset($params['limit']) ? $params['limit'] : 5;
        $list = self::where('user_id', $params['user_id']);
        if (isset($params['type']) && $params['type']) {
            $list = $list->where('type', $params['type']);
        }
        $list = $list->field('id,type,redbag,before,after,memo,createtime')
            ->page((int)$page, (int)$limit)->order('id desc')
            ->select();
        return $list;
    }

    public static function sumIncomeList($params)
    {
        $page = isset($params['page']) ? $params['page'] : 1;
        $limit = isset($params['limit']) ? $params['limit'] : 5;
        $list = self::where('user_id', $params['user_id']);
        $list = $list->whereIn('type', array('邀好友'));
        $list = $list->field('id,redbag,before,after,memo,createtime')
            ->page((int)$page, (int)$limit)->order('id desc')
            ->select();
        return $list;
    }
}